#!/bin/bash

source /home/shell/util.sh

function install () {
    requireJava
    if [ ! -d "/opt/mycat/config/datasources" ]; then
        mkdir -p /opt/mycat/config/datasources
    fi
    if [ ! -d "/opt/mycat/config/clusters" ]; then
        mkdir -p /opt/mycat/config/clusters
    fi
    if [ ! -d "/opt/mycat/config/users" ]; then
        mkdir -p /opt/mycat/config/users
    fi
    if [ ! -f "/opt/mycat/mycat.jar" ]; then
        download /opt/mycat/mycat.jar http://dl.mycat.org.cn/2.0/1.20-release/mycat2-1.20-jar-with-dependencies.jar
    fi

}

function config () {
    cp -f /home/shell/support/mycat/server.json /opt/mycat/config
    cp -f /home/shell/support/mycat/datasources/dr0.datasource.json /opt/mycat/config/datasources
    cp -f /home/shell/support/mycat/datasources/dw0.datasource.json /opt/mycat/config/datasources
    cp -f /home/shell/support/mycat/clusters/c0.cluster.json /opt/mycat/config/clusters
    cp -f /home/shell/support/mycat/users/root.user.json /opt/mycat/config/users
    firewall-addport 8066
}

function run () {
    /opt/jdk/bin/java -Dfile.encoding=UTF-8 -Duser.timezone=GMT+8 -DMYCAT_HOME=/opt/mycat/config -Dorg.slf4j.simpleLogger.defaultLogLevel=DEBUG -jar /opt/mycat/mycat.jar
}


install && config && run





